<template>
  <el-dialog
    class="eldialog"
    :visible.sync="visible"
    :title="title"
    :close-on-click-modal="false"
    append-to-body
    top="10vh"
    :close-on-press-escape="false"
    :before-close="removeSelecteId"
  >
    <el-form ref="roleForm" :model="dataForm" label-width="80px">
      <el-form-item label="角色名称" prop="roleName">
        <el-input v-model="dataForm.roleName" placeholder="请输入角色名称" />
      </el-form-item>
      <!-- <el-form-item label="角色值" prop="description">
        <el-input v-model="dataForm.roleId" />
      </el-form-item> -->
    </el-form>
    <template slot="footer">
      <el-button type="success" size="medium" @click="onSubmit">保存</el-button>
      <el-button type="danger" size="medium" @click="removeSelecteId"
        >取消</el-button
      >
    </template>
  </el-dialog>
</template>
  
  <script>
import { getRoleDetail,getRoleUpdata } from "@/api/datacentersg/achives/documentApi";
import store from "@/store";
export default {
  name: "ModuleAdd",
  data() {
    return {
      title: "编辑角色",
      visible: false,
      dataForm: {
        roleName: "",
        roleId: "",
        parentId: "0",
        description: "",
      },
      checkedId: [],
    };
  },
  mounted() {},

  methods: {
    async initEdit(role) {
      this.getRoleDetail(role.roleId)
      console.log(role, "role");
      this.visible = true;
    },

    getRoleDetail(roleId) {
      console.log(roleId, "rolesss")
      const params = {
        userId: store.getters.user_id.toString(),
        token: store.getters.token.toString(),
        data: {
          roleId: roleId, //父组件传过来的id
        },
      };
      getRoleDetail(params).then((result) => {
        if (result.result) {
          this.dataForm.roleName = result.resultdata.data.roleName; //名字
          this.dataForm.roleId = result.resultdata.data.roleId; //角色值
          this.dialogVisible = true;
        }
      });
    },

    removeSelecteId() {
      this.checkedId = [];
      this.visible = false;
    },
    // 表单提交
    async onSubmit() {
      const params = {
        userId: store.getters.user_id.toString(),
        token: store.getters.token.toString(),
        data:{
            // roleId:this.dataForm.roleId,
            roleName:this.dataForm.roleName,
        }
      }
      getRoleUpdata(params).then((result) => {
        if (result.result) {
          this.$emit("initData");
          this.removeSelecteId();
          this.$message({
            type: "success",
            message: "操作成功",
          });
        } else {
          this.$message({
            type: "error",
            message: result.message,
          });
        }
      });
    },
  },
};
</script>
  
  <style scoped>
</style>
  